﻿#include "scoreboarddialog.h"
#include "ui_scoreboarddialog.h"

ScoreboardDialog::ScoreboardDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ScoreboardDialog)
{
    ui->setupUi(this);
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

    // 标准模式得分记录
    QList<Record> standard_list = ST->standard_record_list();
    ui->tableWidget_standard->setRowCount(standard_list.count());
    ui->tableWidget_standard->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);    // 平均分配列宽
    for (int i = 0; i < standard_list.count(); ++i) {
        auto r = standard_list.at(i);
        ui->tableWidget_standard->setItem(i, 0, new QTableWidgetItem(r.name));
        ui->tableWidget_standard->setItem(i, 1, new QTableWidgetItem(QString::number(r.score)));
        ui->tableWidget_standard->setItem(i, 2, new QTableWidgetItem(r.play_time.toString("hh:mm:ss.z")));
        ui->tableWidget_standard->setItem(i, 3, new QTableWidgetItem(r.record_time.toString("yyyy-MM-dd hh:mm:ss")));
        for (int j = 0; j < 4; ++j) {
            ui->tableWidget_standard->item(i, j)->setTextAlignment(Qt::AlignCenter);
        }
    }

    // 闯关模式得分记录
    QList<Record> pass_list = ST->pass_record_list();
    ui->tableWidget_pass->setRowCount(pass_list.count());
    ui->tableWidget_pass->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);    // 平均分配列宽
    for (int i = 0; i < pass_list.count(); ++i) {
        auto r = pass_list.at(i);
        ui->tableWidget_pass->setItem(i, 0, new QTableWidgetItem(r.name));
        ui->tableWidget_pass->setItem(i, 1, new QTableWidgetItem(QString::number(r.pass_difficulty)));
        ui->tableWidget_pass->setItem(i, 2, new QTableWidgetItem(r.play_time.toString("hh:mm:ss.z")));
        ui->tableWidget_pass->setItem(i, 3, new QTableWidgetItem(r.record_time.toString("yyyy-MM-dd hh:mm:ss")));
        for (int j = 0; j < 4; ++j) {
            ui->tableWidget_pass->item(i, j)->setTextAlignment(Qt::AlignCenter);
        }
    }
}

ScoreboardDialog::~ScoreboardDialog()
{
    delete ui;
}

void ScoreboardDialog::showMode(int mode)
{
    qDebug()<<"得分榜显示"<<mode;
    ui->tabWidget->setCurrentIndex(mode);
}
